//
//  DXsearchView.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/5.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

class DXsearchView: UIView {

    @IBOutlet weak var cancelBtn: UIButton!
    @IBOutlet weak var searchTextFieldConst: NSLayoutConstraint!
    @IBOutlet weak var searchTextField: UITextField!
  
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let leftView =  UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
//        选择填充方式
        leftView.contentMode = .Center
        
        leftView.frame.size.height = searchTextField.frame.height
        leftView.frame.size.width = searchTextField.frame.height
         
        searchTextField.leftView = leftView
        
        searchTextField.leftViewMode = .Always
        
        
    }
    
    @IBAction func cancelBtnClick(sender: UIButton) {
        searchTextField.resignFirstResponder()
         changConstraint( 0)
    }
    
    @IBAction func textFieldEditing(sender: AnyObject) {
        changConstraint( cancelBtn.frame.width)
    }
    
    @objc private func changConstraint(const:CGFloat){
        searchTextFieldConst.constant = const
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }

    }

    class func searchView()->(DXsearchView) {
        
        return NSBundle.mainBundle().loadNibNamed("searchView", owner: nil, options: nil).last as! DXsearchView
 
    }
    

}
